package com.mybatis_puls.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mybatis_puls.demo.entity.Address;
import com.mybatis_puls.demo.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 小🌤
 * @since 2020-12-18
 */
@RestController
@RequestMapping("/address")
public class AddressController {
    @Autowired
    private AddressService addressService;

    @RequestMapping("/info/{id}")
    public Object info(@PathVariable("id")Integer user_id){
        QueryWrapper<Address> wrapper=new QueryWrapper<>();
        wrapper.eq("user_id",user_id);
        List<Address> list = addressService.list(wrapper);
        return list;
    }

    @RequestMapping("/update")
    public Object uodate(Address address){
        addressService.updateById(address);
        return address;
    }
    @RequestMapping("/save")
    public Object save(Address address){
        addressService.save(address);
        return address;
    }

    @RequestMapping("/in/{id}")
    public Object in(@PathVariable("id")Integer id){
        List<Address> list = addressService.listByIds(Arrays.asList(id));
        return list;
    }
}

